package vip.ifmm.lehouse.api.gateway.controller.commodity;

import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import vip.ifmm.lehouse.commodity.service.api.CommodityTypeService;
import vip.ifmm.lehouse.common.dto.ServerResponse;
import vip.ifmm.lehouse.common.model.CommodityType;

/**
 * 商品分类服务控制器
 *
 * @author Fish
 * <p>Email: fishinlove@163.com</p>
 * <p>created by 2019/06/22 15:18:50</p>
 */
@RestController
@RequestMapping(path = "/commodityType")
public class CommodityTypeController {

    @Reference
    private CommodityTypeService commodityTypeService = null;

    @PostMapping(path = "/saveCommodityType")
    ServerResponse saveCommodityType(CommodityType commodityType) {
        return commodityTypeService.saveCommodityType(commodityType);
    }

    @PutMapping(path = "/updateCommodityType")
    ServerResponse updateCommodityType(CommodityType commodityType) {
        return commodityTypeService.updateCommodityType(commodityType);
    }

    @DeleteMapping(path = "/deleteCommodityType")
    ServerResponse deleteCommodityType(Integer id) {
        return commodityTypeService.deleteCommodityType(
                new CommodityType().setCommodityTypeId(id));
    }

    @GetMapping(path = "/listCommodityTypes")
    ServerResponse listCommodityTypes(@RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "16") Integer pageSize,
                                      @RequestParam(defaultValue = "false") boolean needPaged) {
        return commodityTypeService.listCommodityTypes(pageNum, pageSize, needPaged);
    }

    @GetMapping(path = "/getCommodityType")
    ServerResponse getCommodityType(Integer commodityTypeId) {
        return commodityTypeService.getCommodityType(commodityTypeId);
    }
}
